<html>
<head><meta charset="utf-8"><title>Format after Expand Macro · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Format.20after.20Expand.20Macro.html">Format after Expand Macro</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="233421673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Format%20after%20Expand%20Macro/near/233421673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emmanuel Thompson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Format.20after.20Expand.20Macro.html#233421673">(Apr 07 2021 at 02:34)</a>:</h4>
<p>Hey all, I'm investigating how much effort it would be to format after expanding a macro, I found this in the code: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/cf41e1410a0cf87a05b2dd632e3b5d67f8d55327/crates/ide/src/expand_macro.rs#L36-L38">https://github.com/rust-analyzer/rust-analyzer/blob/cf41e1410a0cf87a05b2dd632e3b5d67f8d55327/crates/ide/src/expand_macro.rs#L36-L38</a> , is there alot to accomplish this? Why is whitespace lost and re-added on expansion?</p>



<a name="233422093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Format%20after%20Expand%20Macro/near/233422093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Format.20after.20Expand.20Macro.html#233422093">(Apr 07 2021 at 02:40)</a>:</h4>
<p>The difficult part here is adding a source code formatter in the first place, hooking it up to macros should be fairly straightforward</p>



<a name="233422302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Format%20after%20Expand%20Macro/near/233422302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emmanuel Thompson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Format.20after.20Expand.20Macro.html#233422302">(Apr 07 2021 at 02:43)</a>:</h4>
<p>Ahh because RA LSP calls out to rustfmt?</p>



<a name="233425383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Format%20after%20Expand%20Macro/near/233425383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Format.20after.20Expand.20Macro.html#233425383">(Apr 07 2021 at 03:24)</a>:</h4>
<p>In fact, I am working on this right now, we need a proper ast formatter internally for different purposes.</p>



<a name="233425610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Format%20after%20Expand%20Macro/near/233425610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Format.20after.20Expand.20Macro.html#233425610">(Apr 07 2021 at 03:27)</a>:</h4>
<blockquote>
<p>Why is whitespace lost </p>
</blockquote>
<p>Because our macro expansion code ignores whitespace information and even we preserve it we still need to reformat for proc-macro etc.</p>



<a name="233425689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Format%20after%20Expand%20Macro/near/233425689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edwin Cheng <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Format.20after.20Expand.20Macro.html#233425689">(Apr 07 2021 at 03:28)</a>:</h4>
<blockquote>
<p>Ahh because RA LSP calls out to rustfmt?</p>
</blockquote>
<p>yes</p>



<a name="233426358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Format%20after%20Expand%20Macro/near/233426358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Emmanuel Thompson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Format.20after.20Expand.20Macro.html#233426358">(Apr 07 2021 at 03:37)</a>:</h4>
<p><span class="user-mention" data-user-id="216201">@Edwin Cheng</span> neat! Thanks for the info.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>